package fr.esisar.cs420.swt;

import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;

import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Table;
import org.eclipse.jface.viewers.ArrayContentProvider;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.swt.widgets.Group;

import fr.esisar.cs420.traitement.Commande;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.layout.FormData;

public class AfficherArticlesCommande extends Shell {
	private Table table;

	/**
	 * Launch the application.
	 * @param args
	 */
	public static void main(String args[]) {

	}

	/**
	 * Create the shell.
	 * @param display
	 */
	public AfficherArticlesCommande(Display display) {
		super(display, SWT.SHELL_TRIM);
		setLayout(new FormLayout());
		
		Group grpArticlesDeVotre = new Group(this, SWT.NONE);
		FormData fd_grpArticlesDeVotre = new FormData();
		fd_grpArticlesDeVotre.bottom = new FormAttachment(0, 372);
		fd_grpArticlesDeVotre.right = new FormAttachment(0, 604);
		fd_grpArticlesDeVotre.top = new FormAttachment(0, 10);
		fd_grpArticlesDeVotre.left = new FormAttachment(0, 10);
		grpArticlesDeVotre.setLayoutData(fd_grpArticlesDeVotre);
		grpArticlesDeVotre.setText("Articles de votre commande");
		
		TableViewer tableViewer = new TableViewer(grpArticlesDeVotre, SWT.BORDER | SWT.FULL_SELECTION);
		table = tableViewer.getTable();
		table.setBounds(10, 97, 574, 244);
		
		Label lblNumero = new Label(grpArticlesDeVotre, SWT.NONE);
		lblNumero.setBounds(10, 69, 55, 15);
		lblNumero.setText("Numero");
		
		Label lblTitreAlbumlivre = new Label(grpArticlesDeVotre, SWT.NONE);
		lblTitreAlbumlivre.setText("Titre Album/Livre");
		lblTitreAlbumlivre.setBounds(102, 69, 110, 15);
		
		Label lblFormat = new Label(grpArticlesDeVotre, SWT.NONE);
		lblFormat.setText("Format");
		lblFormat.setBounds(255, 69, 61, 15);
		
		Label lblPrixFormat = new Label(grpArticlesDeVotre, SWT.NONE);
		lblPrixFormat.setText("Prix Format");
		lblPrixFormat.setBounds(368, 69, 110, 15);
		
		Label lblQuantit = new Label(grpArticlesDeVotre, SWT.NONE);
		lblQuantit.setText("Quantité");
		lblQuantit.setBounds(497, 69, 110, 15);
		createContents();
		
		tableViewer.setContentProvider( new ArrayContentProvider());
		tableViewer.setLabelProvider( new LabelProvider());
		StringTokenizer st = new StringTokenizer(AfficherCommandes.element," ");
		int idCommande = Integer.valueOf(st.nextToken());
		List<String> listeArticles = new ArrayList<String>();
		listeArticles = Commande.afficherCommande(idCommande);
		tableViewer.setInput(listeArticles);
		
		
	}

	/**
	 * Create contents of the shell.
	 */
	protected void createContents() {
		setText("Articles");
		setSize(639, 427);

	}

	@Override
	protected void checkSubclass() {
		// Disable the check that prevents subclassing of SWT components
	}
}
